import 'package:carbon/json/article_item.dart';
import 'package:carbon/network/user_api.dart';
import 'package:carbon/widgets/confirmDialog.dart';
import 'package:flutter/material.dart';

class ArticlePage extends StatefulWidget {
  const ArticlePage({super.key});

  @override
  State<ArticlePage> createState() => _ArticlePageState();
}

class _ArticlePageState extends State<ArticlePage> {
  TextEditingController _accountNameController = TextEditingController();
  TextEditingController _pwdController = TextEditingController();
  GlobalKey _formKey =GlobalKey<FormState>();
  UserApi userApi = new UserApi();
  int selectRadioValue = 0;

  @override
  Widget build(BuildContext context) {
    List route_args = ModalRoute.of(context)?.settings.arguments as List;
    ArticleItem item = route_args[0];
    int index = route_args[1];
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            backgroundColor: Color(int.parse("04a461",radix:16)).withAlpha(255),
            expandedHeight: 140,
            flexibleSpace: FlexibleSpaceBar(
              background: Image.asset("assets/imgs/index${(index+1)}.png",fit: BoxFit.cover),
            ),
            // pinned: true,//固定显示
            floating: true,//用户下拉时会自然消失视野，但是有上拉操作时，就会显现该区域
            // snap: true,//要和floating结合使用，但是我们 appBar区域较小，看不出差别
          ),
          SliverPadding(padding: EdgeInsets.only(bottom: 12)),
          SliverToBoxAdapter(
              child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
                  child: Column(
                    children: [
                      Text("${item.title}",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),),
                      Padding(padding: EdgeInsets.only(bottom: 15)),
                      Text("作者：${item.author}"),
                      Padding(padding: EdgeInsets.only(bottom: 15)),

                      Text("${item.content.substring(item.title.length).trim()}"),
                      Padding(padding: EdgeInsets.only(bottom: 15)),
                      Container(
                        width: double.infinity,
                        alignment: AlignmentDirectional.centerEnd,
                        child: Text("发布时间：${item.createdTime}",style: TextStyle(color: Colors.grey.shade600),),
                      )
                    ],
                  )
              )
          ),
        ],
      ),
    );
  }


}
